const { Model, DataTypes, Sequelize } = require('sequelize')
const db = require('../core/db')
const { CustomError } = require("../core/common")
class Blog extends Model {

}
const xss = require("xss");

Blog.init({
    content: {
        type: DataTypes.TEXT,
        allowNull: false,
        set(value) {
            if (!value.length) {
                throw new CustomError('内容不能为空', 402)
            }
            //防止xss攻击
            this.setDataValue("content", xss(value))
        },
        validate: {
            notEmpty: {
                msg: '内容不能为空'
            },
        },
        comment: "内容"
    },
}, {
    sequelize: db,
    modelName: 'Blog' // 我们需要选择模型名称
})
module.exports = Blog
